import Navigate2enterpriseAnalysis from '@/mixins/navigate2enterpriseAnalysis'

export default {
  mixins: [Navigate2enterpriseAnalysis],
  data () {
    return {
      barClickHandlerKey: 'districtCode'
    }
  },
  beforeDestroy () {
    this.unbindBarClickEvent()
  },
  mounted () {
    this.bindBarClickEvent()
  },
  methods: {
    barClickHandler (e) {
      const data = {}
      if (data[this.barClickHandlerKey]) {
        this.navigateToEnterpriseAnalysis({ id: data.code }, this.barClickHandlerKey)
      }
    },
    bindBarClickEvent () {
      const chart = this.$refs.chart && this.$refs.chart.chart
      if (chart) {
        chart.on('click', this.barClickHandler)
      }
    },
    unbindBarClickEvent () {
      const chart = this.$refs.chart && this.$refs.chart.chart
      if (chart) {
        chart.off('click', this.barClickHandler)
      }
    },
  },
}
